home *** CD-ROM | disk | FTP | other *** search
- Path: news.ti.com!usenet
- From: Chuach@dlep1.itg.ti.com (Chua Chye Heng)
- Newsgroups: comp.lang.c++
- Subject: Re: HELP!! How to correctly pass member functions to a C function???
- Date: Wed, 10 Apr 1996 08:02:25 GMT
- Organization: Texas Instruments
- Message-ID: <4kfslu$s1t@tilde.csc.ti.com>
- References: <4kf534$csn@tilde.csc.ti.com>
- NNTP-Posting-Host: 137.167.42.30
- X-Newsreader: Forte Free Agent 1.0.82
-
- Chuach@dlep1.itg.ti.com (Chua Chye Heng) wrote:
-
- A little more info:
-
- 1. when I declared the method to be static, the calling went thro'
- But I am unable to call non-static members in the static method
-
- 2. I declared a C function wrapper to indirectly call the method.
- However, the this pointer is no longer valid when the method is being
- called. I have to save the this pointer and cast it to the right class
- type in order to call other member within that method.
-
- Anyone have a better solution??
-
- >Hi,
-
- >I need to use a function in a c library which search some database and
- >invoke the user defined function to process them in my c++ program.
- > /* c function prototype */
- > search( int (*norm_func)(), int (*err_func)());
-
- >My class definitions are as follows:
- >extern "C" {
- >#include "C-function.h"
- >}
-
- >class base {
- >...
- >public:
- > int process();
- > virtual int good_handle( data* pData ) = 0;
- > virtual int bad_handle( char* msg )=0;
- >}
-
- >class derived : public base {
- >...
- >public:
- > int good_handle( data* pData );
- > int bad_handle( char* msg);
- >}
-
- >I use the process method in the base class to invoke the C function
- >like this:
- > search ( (int(*)())this->good_handle, (int(*)())this->bad_handle);
-
- >When the program executes, the good_handle method in the derived class
- >did get called. BUT the data* pData points to some "&^%$#" instead!!
- >I did try to use a normal C program to test out the library and it is
- >working fine.
-
- >Can some kind people help me out of this?? My project schedule is
- >falling on me..... HELP
-
- >Deeply appreciate any hints or help..
-
- >BTW, I also try to use a normal C function to wrap around the two
- >method but it also fail
- > base* pBase;
- > int good( ...) { pBase->good_handle(...); }
- > int bad(...) { pBase->bad_handle(...); }
- > and called them in process as:
- > search (good_handle, bad_handle);
-
-
- >===========================================================
- >Chye Heng
- >Email: Chuach@dlep1.itg.ti.com
- >Voice: 065-2902460
-
-
-
-
- ===========================================================
- Chye Heng
- Email: Chuach@dlep1.itg.ti.com
- Voice: 065-2902460
-
-
-